package com.bwie.parkdemo.mvvm.ui.activity;

import android.content.Intent;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.bwie.lib_core.action.ActActionField;
import com.bwie.lib_core.mvvm.base.BaseActivity;
import com.bwie.parkdemo.BR;
import com.bwie.parkdemo.R;
import com.bwie.parkdemo.databinding.ActivityAddvisitorBinding;
import com.bwie.parkdemo.mvvm.viewmodel.AddVisitorVideModel;

/**
 * 添加来访申请界面
 * */
public class AddVisitorActivity extends BaseActivity<ActivityAddvisitorBinding,AddVisitorVideModel> {

    @Override
    public int initLayout() {
        return R.layout.activity_addvisitor;
    }

    @Override
    public void initView() {
        //由于当前界面作用为添加来访申请以及修改来访申请
        //通过Intent传参方式获取还要修改的内容
        //由于界面跳转传参全部封装到基类的bundle中，所以
        //bundle为空添加数据;不为空修改数据
        Bundle bundle = getIntent().getBundleExtra(ActActionField.ACTBUNDLE);
        if (bundle != null){
            //从申请详情跳转过来，进行修改操作
            vm.bundle = bundle;
        }
        //通过datatbinding向xml中设置单项绑定数据封装实体类，以及对应控件监听器
        v.setEntity(vm.getAddVisitorBindEntity());
        v.setListener(vm.listener);
    }

    @Override
    public int initVariable() {
        return BR.vm;
    }
    protected Bundle resultBundle;
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.e("ZXWQ","onActivityResult:");
        if (requestCode == 100 && resultCode == RESULT_OK){
            resultBundle = data.getBundleExtra(ActActionField.ACTBUNDLE);
            int parkId = resultBundle.getInt("parkId");
            String parkName = resultBundle.getString("parkName");
            if (parkId!=0) {
                Log.e("ZXWQ", "onActivityResult:" + parkId + "&&&" + parkName);
                vm.getAddVisitorBindEntity().setPartName(parkName);
                vm.getAddVisitorBindEntity().parkId = parkId;
            }
            int carId = resultBundle.getInt("carId");
            String carNum = resultBundle.getString("carNum");
            if (carId != 0) {
                Log.e("ZXWQ", "onActivityResult:" + carId + "&&&" + carNum);
                vm.getAddVisitorBindEntity().setCarNum(carNum);
            }
        }
    }
}
